<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../include/taglib.jsp" %>

<table class="table table-striped table-advance table-hover">
    <thead>
    <tr>
        <th>ID</th>
        <th>登录账号</th>
        <th>真实姓名</th>
        <th>邮箱</th>
        <th>电话</th>
        <th>部门</th>
        <th>分级</th>
        <th>状态</th>
        <th>注册时间</th>
        <th>角色</th>
        <th style="width: 15%">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach var="sysUser" items="${pages.result}" varStatus="s">
        <tr>
            <td><font color="blue">${s.index+1}</font><input type="hidden" value="${sysUser.id}"></td>
            <td>${sysUser.loginName}</td>
            <td>${sysUser.realName}</td>
            <td>${sysUser.email}</td>
            <td>${sysUser.telephone}</td>
            <td>${sysUser.department}</td>
            <td>
                <strong>
                    <c:choose>
                        <c:when test="${sysUser.level == 0}">①</c:when>
                        <c:when test="${sysUser.level == 1}">②</c:when>
                        <c:when test="${sysUser.level == 2}">③</c:when>
                        <c:when test="${sysUser.level == 3}">④</c:when>
                        <c:when test="${sysUser.level == 4}">⑤</c:when>
                        <c:when test="${sysUser.level == 5}">⑥</c:when>
                    </c:choose>
                </strong>
            </td>
            <td>
                <c:if test="${sysUser.state == 1}">
                    <label class="label label-success">正常</label>
                    <c:if test="${loginUser.level < sysUser.level}">
                        <button class='btn btn-default btn-xs' onclick="changeState(this);">
                            <input type="hidden" value="${sysUser.id}">
                            <i class="fa fa-toggle-on fa-2x"></i>
                        </button>
                    </c:if>
                </c:if>
                <c:if test="${sysUser.state != 1}">
                    <label class="label label-danger">禁用</label>
                    <c:if test="${loginUser.level < sysUser.level}">
                        <button class='btn btn-default btn-xs' onclick="changeState(this);">
                            <input type="hidden" value="${sysUser.id}">
                            <i class="fa fa-toggle-off fa-2x"></i>
                        </button>
                    </c:if>
                </c:if>
            </td>
            <td><fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${sysUser.registerDate}"/></td>
            <td>
                    ${sysUser.roleDetail}
            </td>
            <td>
                <c:if test="${loginUser.level < sysUser.level}">
                    <button onclick="editRoles(${sysUser.id});" title="修改用户角色" class="btn btn-theme03 btn-xs"
                            data-toggle="modal"
                            data-target="#myModal">
                        <i class="fa fa-user-circle fa-2x"></i>
                    </button>
                    <button onclick="edit(${sysUser.id});" title="修改用户信息" class="btn btn-primary btn-xs"
                            data-toggle="modal"
                            data-target="#myModal">
                        <i class="fa fa-pencil fa-2x"></i>
                    </button>
                    &nbsp;
                    <button title="删除用户" class="btn btn-danger btn-xs" onclick="del(${sysUser.id});">
                        <i class="fa fa-trash-o fa-2x"></i>
                    </button>
                    <button title="重置用户密码" class="btn btn-danger btn-xs"
                            onclick="resetPwd(${sysUser.id});">
                        <i class="fa fa-refresh fa-2x"></i>
                    </button>
                </c:if>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>

<div class="col-md-12">
    <%@include file="../include/page.jsp" %>
</div>
<script type="text/javascript">
    function changeState(obj) {
        var id = $(obj).find("input").val();
        var package = new AJAXPacket("${ctx}/sysuser/changeState")
        package.data.add("id", id);
        core.ajax.sendPacket(package, function (response) {
            if (response.data.success) {
                alertMsg.correct("成功！");
                jumpPageTo('_list');
            } else {
                alertMsg.error(response.data.errMsg);
            }
        });
        package = null;
    }

    function editRoles(id) {
        var package = new AJAXPacket("${ctx}/sysuser/editRoles");
        package.data.add("id", id);
        core.ajax.dynamicLoadpage(package, "editPage");
        package = null;
    }
</script>
